/** @file igxBug.h
  *
  * @brief This file contains definitions for debugging macro
  * of Bluetooth driver.
  * 
  * (c) Copyright 2003-2007, Marvell International Ltd.
  * All Rights Reserved
  */

#ifndef _IXBUG_H_
#define _IXBUG_H_

#ifdef __cplusplus
extern "C" {
#endif //__cplusplus


#ifndef DEFINE_DEBUG_VARS
extern ULONG DebugLevel;                    // this must be defined somewhere in drvr.
extern unsigned long long DebugModule;
#endif

//Define debug Level
#define DBG_NONE        0x0                 // 
#define DBG_ERROR       (1<<0)              // Debug for ERRORS
#define DBG_WARNING     (1<<1)              // Debug for Warnings.
#define DBG_HELP        (1<<2)              // Debug for driver load   

//Define debug module
#define DBG_LOAD        (1<<3)
#define DBG_UNLOAD      DBG_LOAD            // Debug for driver unload.
#define DBG_ISR         (1<<4)              // Debug for ISR messages.
#define DBG_TX          (1<<5)              // Transmit data path debug
#define DBG_TX_DUMP     (1<<6)              // Transmit data dump.
#define DBG_RX          (1<<7)              // Receive data path debug.
#define DBG_RX_DUMP     (1<<8)              // Receive data dump.
#define DBG_BUF         (1<<9)              // Debug buffer, memory, resource management
#define DBG_HCI         (1<<10)             // Debug HCI functions
#define DBG_CMD         (1<<11)             // Debug Marvell BT Command and Event
#define DBG_CMD_DUMP    (1<<12)             // Debug Marvell BT Command and Event
#define DBG_PS          (1<<13)             // Debug PS State

#define DBG_USER0       (1LL<<63)

#define DBG_ALL         0xffffffffffffffffLL         // All debug enabled.

#define DBG_LVLDEFAULT (DBG_ERROR \
| DBG_WARNING \
| DBG_HELP)

#define DBG_MDLDEFAULT (DBG_LOAD|DBG_CMD|DBG_CMD_DUMP|DBG_PS)


#ifdef MRVL_PRINT_DBG_MSG

#ifdef DBG_MSG_TO_RETAILMSG 
void MrvRETAILMSG(const wchar_t *fmt, ...);  
#define DBGPRINT(lvl, Str)\
{\
    unsigned long long __lvl = lvl;\
    if ((__lvl & DBG_ERROR) ||\
        ((DebugLevel & __lvl) && (DebugModule & __lvl)) ||\
        (((__lvl & (DBG_ERROR|DBG_WARNING|DBG_HELP)) == DBG_NONE) && (DebugModule & __lvl)))\
    {\
			MrvRETAILMSG Str;\
    }\
}\

#else //DBG_MSG_TO_RETAILMSG

void MrvPrintFile(const unsigned short *fmt, ...);
#define DBGPRINT(lvl, Str)\
{\
    unsigned long long __lvl = lvl;\
    if ((__lvl & DBG_ERROR) ||\
        ((DebugLevel & __lvl) && (DebugModule & __lvl)) ||\
        (((__lvl & (DBG_ERROR|DBG_WARNING|DBG_HELP)) == DBG_NONE) && (DebugModule & __lvl)))\
    {\
        MrvPrintFile Str;\
    }\
}\

#endif //DBG_MSG_TO_RETAILMSG
 
#define MRV_DRV_LINE_LENGTH 16
static
void HexDump(unsigned long long dbgLevel, char *msg, unsigned char *buf, int len)
{
    int i, j;
    unsigned char lastBuf[MRV_DRV_LINE_LENGTH];

    if (msg)
        DBGPRINT(dbgLevel, (L"%S - hexdump(len=%d):\n\r", msg, len));

    // new version that prints out correctly in dbgview
    j = len / MRV_DRV_LINE_LENGTH;
    for (i = 0; i < j; i++)
    {
        // note: if MRV_DRV_LINE_LENGTH changes, the following format
        //       needs to change as well
        DBGPRINT(dbgLevel, (L"%02x %02x %02x %02x %02x %02x %02x %02x - %02x %02x %02x %02x %02x %02x %02x %02x\n\r",
                            (UCHAR)*buf,      (UCHAR)*(buf+1),  (UCHAR)*(buf+2),  (UCHAR)*(buf+3),
                            (UCHAR)*(buf+4),  (UCHAR)*(buf+5),  (UCHAR)*(buf+6),  (UCHAR)*(buf+7),
                            (UCHAR)*(buf+8),  (UCHAR)*(buf+9),  (UCHAR)*(buf+10), (UCHAR)*(buf+11),
                            (UCHAR)*(buf+12), (UCHAR)*(buf+13), (UCHAR)*(buf+14), (UCHAR)*(buf+15)));
        buf+= MRV_DRV_LINE_LENGTH;
    }

    j = len % MRV_DRV_LINE_LENGTH;

    if (j != 0)
    {
        for (i = 0; i < j; i++)
        {
            lastBuf[i] = *(buf+i);
        }

        for (i = j; i < MRV_DRV_LINE_LENGTH; i++)
        {
            lastBuf[i] = 0;
        }

        DBGPRINT(dbgLevel, (L"%02x %02x %02x %02x %02x %02x %02x %02x - %02x %02x %02x %02x %02x %02x %02x %02x\n\r",
                            (UCHAR)lastBuf[0],  (UCHAR)lastBuf[1],  (UCHAR)lastBuf[2],  (UCHAR)lastBuf[3],
                            (UCHAR)lastBuf[4],  (UCHAR)lastBuf[5],  (UCHAR)lastBuf[6],  (UCHAR)lastBuf[7],
                            (UCHAR)lastBuf[8],  (UCHAR)lastBuf[9],  (UCHAR)lastBuf[10], (UCHAR)lastBuf[11],
                            (UCHAR)lastBuf[12], (UCHAR)lastBuf[13], (UCHAR)lastBuf[14], (UCHAR)lastBuf[15]));
    }
}
 
#else   //MRVL_PRINT_DBG_MSG

#define DBGPRINT(lvl, Str)
#define HexDump(dbglevel, msg, buf, size)

#endif  //MRVL_PRINT_DBG_MSG


#ifdef __cplusplus
}
#endif //__cplusplus

#endif  //_IXBUG_H_



